package powerws

import (
	"power/core/service/graph"

	"github.com/RocksonZeta/hubx"
)

const (
	PropUser = "user"
)

type User struct {
	Id    int
	Name  string
	Icon1 string
	Icon2 string
}

func getUser(client *hubx.Client) User {
	user, ok := client.Props.Load(PropUser)
	if ok {
		return user.(User)
	}
	return User{}
}

const (
	RoleAdmin    = "admin"
	RoleTeacher  = "teacher"
	RolePlayer   = "player"
	RoleObserver = "observer"
)

var observerMsg = map[string]bool{
	"im": true, //即时消息
}

var playerMsg = map[string]bool{
	"im": true,
}

type Node struct{}
type Edge struct{}

type initMsg struct {
	Id       int
	Graph    graph.Graph
	Elements []graph.GraphElement
	Protos   []graph.GraphElementProtoClass
}

const (
	graphInit          = "graph_init"
	graphLoad          = "graph_load"
	graphUpdate        = "graph_update"
	elementNew         = "element_new"
	elementDelete      = "element_delete"
	elementUpdateProps = "element_update_props"
	elementUpdateData  = "element_update_data"
	// nodeUpdate         = "node_update"
	// nodeDelete         = "node_delete"
	// nodePositionUpdate = "node_position_update"
	// edgeNew            = "edge_new"
	// edgeUpdate         = "edge_update"
	// edgeDelete         = "edge_delete"
)

type elementNewMsg struct {
	ProtoId int
	Props   graph.Props //must be json
	Sender  string
	TempId  string //node temp id
}
type elementNewMsgOut struct {
	Element graph.GraphElement
	Sender  string
	TempId  string
}
type elementDeleteMsg struct {
	Ids []int
}
type elementUpdateMsg struct {
	Id     int
	Sender string      //哪一个客户端发出的
	Props  graph.Props //must be json
}

type graphUpdateMsg struct {
	Name  string
	Props graph.Props
}
